<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>

<head>
    <base href="<%=basePath%>"/>
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="view/bootstrap-3.3.5/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="view/bootstrapvalidator/css/bootstrapValidator.css" />
    <script charset="utf-8" src="view/jquery/jquery-1.10.2.min.js"></script>
    <script charset="utf-8" src="view/bootstrap-3.3.5/js/bootstrap.js"></script>
    <script charset="utf-8" src="view/bootstrapvalidator/js/bootstrapValidator.js"></script>
</head>
<body>

<!-- 搜索 -->
<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">我的购买申请单</h4>
    </div>
    <div class="panel-body">
        <form action="" id="seachform" method="post"
              class="form-horizontal" role="form">

            <div class="form-group">
                <div class="col-md-5">
                    <label for="docNo" class="col-md-4 control-label">申请单号</label>
                    <div class="col-md-8">
                        <input type="text" id="docNo" name="docNo" class="form-control"
                               placeholder="请输入申请单号" value=""> <input
                            type="hidden" name="page" id="page" value="0">
                        <input type="hidden" name="pageSize" id="pageSize"
                               value="5">
                    </div>
                </div>
                <div class="col-md-5">
                    <label class="col-md-4 control-label">申请单状态</label>
                    <div class="col-md-8">
                        <select name="status" class="form-control">
                            <option value="">--申请单状态--</option>
                            <option value="B">--待报价--</option>
                            <option value="W">--未提交--</option>
                            <option value="S">--审批中--</option>
                            <option value="Y">--审批通过--</option>
                            <option value="N">--审批不通过--</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group">

                <div class="col-md-5">
                    <label class="col-md-4 control-label">提交时间</label>
                    <div class="col-md-8">
                        <input type="date" id="submitDate" name="submitDate"
                               class="form-control" value="">
                    </div>
                </div>

                <div class="col-md-5">
                    <label class="col-md-4 control-label"></label>
                    <div class="col-md-8">
                        <button type="submit" class="btn btn-success">搜索购买申请</button>

                    </div>
                </div>
            </div>

        </form>
    </div>
</div>


<!-- 列表 -->
<div class="panel panel-primary">
    <table class="table table-bordered table-hover">
        <thead>
        <tr class="thead-blue" align="center">
            <td>申请单编号</td>
            <td>申请单创建人</td>
            <td>申请单申请人</td>
            <td>创建时间</td>
            <td>提交时间</td>
            <td>申请单状态</td>
            <td>操作</td>
        </tr>
        </thead>
        <c:forEach items="${list}" var="gm">
            <tr>
                <td>${gm.docNo}</td>
                <td>${gm.empcj.empName}</td>
                <td>${gm.empsq.empName}</td>
                <td>${gm.createDate}</td>
                <td>
                    <c:if test="${gm.submitDate==null}">未提交</c:if>
                    <c:if test="${gm.submitDate!=null}">${gm.submitDate}</c:if>
                </td>
                <td>
                    <c:if test="${gm.status=='B'}">待报价</c:if>
                    <c:if test="${gm.status=='W'}">未提交</c:if>
                    <c:if test="${gm.status=='S'}">审批中</c:if>
                    <c:if test="${gm.status=='Y'}">审批通过</c:if>
                    <c:if test="${gm.status=='N'}">审批未通过</c:if>
                </td>
                <td>
                    <c:if test="${gm.status=='B'}">
                        <button onclick="deletecard(${gm.oid})" data-toggle="modal" data-target="#confirmModal">删除
                        </button>
                        <a href="zcgm/tobaojia?oid=${gm.oid}">去报价</a></c:if>
                    <c:if test="${gm.status=='W'}"><a
                            href="zcgm/tijiao?oid=${gm.oid}&status=W">提交</a>/<a href="zcgm/toupdate?oid=${gm.oid}">修改</a>/<button onclick="deletecard(${gm.oid})" data-toggle="modal" data-target="#confirmModal">删除 </button></c:if>
                    <c:if test="${gm.status=='S'}"><a
                            href="zcgm/toupdate?oid=${gm.oid}">修改</a>/
                        <button onclick="deletecard(${gm.oid})" data-toggle="modal" data-target="#confirmModal">删除</button>
                    </c:if>
                    <c:if test="${gm.status=='Y'}">
                        <button onclick="deletecard(${gm.oid})" data-toggle="modal" data-target="#confirmModal">删除
                        </button>
                    </c:if>
                    <c:if test="${gm.status=='N'}">
                        <button onclick="deletecard(${gm.oid})" data-toggle="modal" data-target="#confirmModal">删除 </button>
                    </c:if>
                </td>
            </tr>

        </c:forEach>
        <tr>
            <td colspan="7">
                <button class="btn btn-primary btn-xs pull-right" data-toggle="modal" data-target="#myModal">资产购买
                </button>
            </td>
        </tr>
    </table>


</div>


<!-- 资产购买申请添加页面 -->

<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <form action="zcgm/insert" id="form" class="form-horizontal"
          method="post" role="form">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">&times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">移动资产购买添加页面</h4>
                </div>
                <div class="modal-body" id="infordiv">
                    <div class="col-md-12">
                        <label class="col-sm-2 control-label">申请单号</label>
                        <div class="col-md-4">
                            <font color="red">待生成...</font>
                        </div>


                        <label class="col-sm-2 control-label">创建人</label>
                        <div class="col-md-4">
                            <input type="hidden" class="form-control" name="creator"
                                   value="1" readonly=" readonly">
                            <input type="text" class="form-control" name="creator1"
                                   value="admin" readonly=" readonly">
                        </div>
                    </div>
                    <div class="col-md-12">
                        <label class="col-sm-2 control-label">审批流程</label>
                        <div class="col-md-4">

                            <select id="sb" class="form-control" name="flowid">
                                <option value="">请选择审批流程</option>
                                <c:forEach items="${lclist }" var="lc">
                                    <option value="${lc.oid }">${lc.flowName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <label class="col-md-2">数据类型</label>
                        <div class="col-md-4">
                            <input type="text" class="form-control" name="doctype">
                        </div>
                    </div>
                    <div class="col-md-12">
                        <label class="col-sm-2 control-label">选择部门</label>
                        <div class="col-md-4">
                            <select class="form-control" name="deptid" id="deptid">
                                <option value="">请选择部门</option>
                                <c:forEach items="${deptlist }" var="d">
                                    <option value=" ${d.oid }">${d.deptName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <label class="col-sm-2 control-label">申请人</label>
                        <div class="col-md-4">

                            <select id="semp" class="form-control" name="proposer">
                                <option value="">请选择申请人</option>
                                <c:forEach items="${emplist }" var="emp">
                                    <option value=" ${emp.oid }">${emp.empName}</option>
                                </c:forEach>
                            </select>
                        </div>

                    </div>

                    <div class="col-md-12">
                        <label class="col-md-2">采购原因</label>
                        <div class="col-md-4">
                            <input type="text" class="form-control" name="reason">
                        </div>
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-md-4">
                            <textarea name="remark" class="form-control"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <button type="button" onclick="Inserttable()"
                                class="btn btn-primary">添加移动明细
                        </button>
                    </div>


                </div>
                <div class="modal-footel">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">提交申请</button>
                </div>
            </div>
        </div>
    </form>
</div>
<%--//购买明细--%>
<div id="demodiv" class="form-group" style="display: none">
    <div class="col-md-12">
        <label class="col-md-2">资产名称</label>
        <div class="col-md-3">
            <input type="text" name="assetName" class="form-control">
        </div>

        <label class="col-md-2">序列号</label>
        <div class="col-md-3">
            <input type="text" class="form-control" name="assetNumber">
        </div>
    </div>
    <div class="col-md-12">
        <label class="col-md-2">规格说明</label>
        <div class="col-md-3">
            <input type="text" class="form-control" name="guige">
        </div>

        <label class="col-md-2">申购数量</label>
        <div class="col-md-3">
            <input type="text" class="form-control" name="shengou">
        </div>
    </div>
    <div class="col-md-12">
        <label class="col-md-2">单价</label>
        <div class="col-md-3">
            <input type="text" class="form-control" name="unitPrice">
        </div>

        <label class="col-md-2">数量</label>
        <div class="col-md-3">
            <input type="text" class="form-control" name="quantity">
        </div>
    </div>

    <div class="col-md-12">
        <label class="col-md-2">购买日期</label>
        <div class="col-md-2">
            <font color="red">...待生成</font>
        </div>
        <div class="col-md-2">
            <button type="button" onclick="remove(this)" class="btn btn-primary">删除</button>
        </div>
    </div>

</div>

<div id="alertmsg" class="alert alert-danger" style="text-align: center;" hidden="true"></div>

</body>
<%@include file="../modal/confirm.jsp" %>
<script type="text/javascript">
    function Inserttable() {
        var demodiv = $("#demodiv").clone(true);
        demodiv.attr("id", "");
        demodiv.show();
        demodiv.appendTo($("#infordiv"));
    }

    function remove(r) {
        $(r).parent().parent().parent().remove();
    }

    $("#deptid").change(function () {

        $.getJSON("zcyd/selectjl", {deptid: $("#deptid").val()}, function (msg) {
            console.log(msg)
            var emp = $("#semp")[0];
            emp.options.length = 1;
            for (var i = 0; i < msg.length; i++) {
                var emp1 = msg[i];
                emp.options.add(new Option(emp1.empName, emp1.oid));
            }
        });
    });


    var deleteoid;

    function deletecard(oid) {
        deleteoid = oid;
    }

    function deleteConfirm() {
        $.get("zcgm/delete", {"oid": deleteoid}, function (s) {
            if (s == true) {
                document.location.href = "zcgm/select";
            } else {
                $("#alertmsg").text("删除失败!该资产有购买明细!");
                $("#alertmsg").slideDown();
                $("#alertmsg").delay(2000).slideUp();
            }
        }).complete(function (xhr) {
            if (xhr.status == "403") {//没有权限
                document.location.href = xhr.getResponseHeader("url");
            } else if (xhr.status != "200") {
                console.log("服务器错误!");
            }
        });

    }

</script>
</html>

